//
//  CheckoutCounterViewController.m
//  EastMarket
//
//  Created by 李鹏程 on 16/11/25.
//  Copyright © 2016年 guoguo. All rights reserved.
//

#import "CheckoutCounterViewController.h"

@interface CheckoutCounterViewController ()
{
    UILabel *lblRechargeAmount;
}
@end

@implementation CheckoutCounterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"咪族购收银台";
    self.view.backgroundColor = EastMarket_backgroundColor;
    
//    [GlobalUnit showAlertHint:@"当前订单id为：" message:_strItemId];
    [self initCheckoutCounterUI];
}

- (void)initCheckoutCounterUI {
    
    CGFloat viewHeight = 44.0f;
    CGFloat spacing = 8.0f;
    CGFloat border = 1.0f;
    
    UIView *viewRechargeAmount = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, viewHeight)];
    viewRechargeAmount.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewRechargeAmount];
    
    UILabel *lblRechargeAmountLeft = [[UILabel alloc] initWithFrame:CGRectMake(spacing, 0, (viewRechargeAmount.frame.size.width - 2 * spacing - border) / 2, viewRechargeAmount.frame.size.height)];
    lblRechargeAmountLeft.text = @"订单总金额:";
    lblRechargeAmountLeft.textColor = EastMarket_darkGreyFontColor;
    [viewRechargeAmount addSubview:lblRechargeAmountLeft];
    
    lblRechargeAmount = [[UILabel alloc] initWithFrame:CGRectMake(lblRechargeAmountLeft.frame.origin.x + lblRechargeAmountLeft.frame.size.width + border, 0, (viewRechargeAmount.frame.size.width - 2 * spacing - border) / 2, viewRechargeAmount.frame.size.height)];
    lblRechargeAmount.text = [NSString stringWithFormat:@"￥%.2lf元", _strCurAmount.floatValue];
    lblRechargeAmount.textColor = EastMarket_MainToneColor;
    lblRechargeAmount.textAlignment = NSTextAlignmentRight;
    [viewRechargeAmount addSubview:lblRechargeAmount];
    
    UIView *viewWXPay = [[UIView alloc] initWithFrame:CGRectMake(0, viewRechargeAmount.frame.origin.y + spacing * 2 + viewRechargeAmount.frame.size.height, SCREEN_WIDTH, viewHeight)];
    viewWXPay.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewWXPay];
    [self addSubDetailViews:viewWXPay iconName:@"微信" iconLeft:8 title:@"微信" titleLeft:36 hint:@""];
    UITapGestureRecognizer *tapViewWXPay = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapViewWXPay:)];
        [viewWXPay addGestureRecognizer:tapViewWXPay];
    [viewWXPay addGestureRecognizer:tapViewWXPay];
    
    UIView *viewLLPay = [[UIView alloc] initWithFrame:CGRectMake(0, viewWXPay.frame.origin.y + border + viewWXPay.frame.size.height, SCREEN_WIDTH, viewHeight)];
    viewLLPay.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewLLPay];
    [self addSubDetailViews:viewLLPay iconName:@"银联" iconLeft:8 title:@"银联" titleLeft:36 hint:@""];
    UITapGestureRecognizer *tapViewLLPay = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapViewLLPay:)];
    [viewLLPay addGestureRecognizer:tapViewLLPay];
    
    UIView *viewCashPay = [[UIView alloc] initWithFrame:CGRectMake(0, viewLLPay.frame.origin.y + border + viewLLPay.frame.size.height, SCREEN_WIDTH, viewHeight)];
    viewCashPay.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewCashPay];
    [self addSubDetailViews:viewCashPay iconName:@"货到付款" iconLeft:8 title:@"货到付款" titleLeft:36 hint:@""];
    UITapGestureRecognizer *tapViewCashPay = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapViewCashPay:)];
    [viewCashPay addGestureRecognizer:tapViewCashPay];
}


//各条件view块添加详细内容
-(UILabel *)addSubDetailViews:(UIView *)parentView iconName:(NSString *)imageName iconLeft:(CGFloat)iconX title:(NSString*)titleName titleLeft:(CGFloat)titleX hint:(NSString*)hintText{
    //开头图标
    UIImageView *viewIcon = [[UIImageView alloc] initWithFrame:CGRectMake(iconX, 0, 20, 20)];
    [parentView addSubview:viewIcon];
    viewIcon.center = CGPointMake(viewIcon.center.x, parentView.frame.size.height/2);
    [viewIcon setImage:[UIImage imageNamed:imageName]];
    
    //标题
    UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(titleX, 0, 160, 32)];
    [parentView addSubview:lblTitle];
    lblTitle.center = CGPointMake(lblTitle.center.x, parentView.frame.size.height/2);
    lblTitle.numberOfLines = 1;
    lblTitle.text = titleName;
    lblTitle.lineBreakMode = NSLineBreakByWordWrapping;
    //lblTitle.textColor = [UIColor colorWithRed:167.0/255 green:167.0/255 blue:167.0/255 alpha:1];
    [lblTitle setTextColor:[UIColor blackColor]];
    lblTitle.backgroundColor =[UIColor clearColor];
    lblTitle.font = [UIFont fontWithName:@"Arial" size:16];
    
    //右箭头  15*15，距离右边也是15
    UIImageView *viewArrow = [[UIImageView alloc] initWithFrame:CGRectMake(parentView.frame.size.width-15-15, 0, 15, 15)];
    
    viewArrow.center = CGPointMake(viewArrow.center.x, parentView.frame.size.height/2);
    [viewArrow setImage:[UIImage imageNamed:@"rightArrow"]];
    
    //内容，初始化时为提示文字
    CGFloat left = 62;
    if ([GlobalUnit isBlankString:hintText]) {
        [parentView addSubview:viewArrow];
    } else {
        
        left = SCREEN_WIDTH - 64 - 24;
    }
    
    UILabel *lblContent = [[UILabel alloc] initWithFrame:CGRectMake(left, 0, viewArrow.frame.origin.x - left - 15 + 15 + 16, 22 + 8)];
    [parentView addSubview:lblContent];
    lblContent.center = CGPointMake(lblContent.center.x, parentView.frame.size.height/2);
    lblContent.text = hintText;
    lblContent.textColor = EastMarket_darkGreyFontColor;
    lblContent.backgroundColor =[UIColor clearColor];
    lblContent.textAlignment = NSTextAlignmentRight;
    lblContent.font = [UIFont fontWithName:@"Arial" size:16];
    
    return lblContent;
}

//各条件view块添加详细内容
-(UILabel *)addSubDetailViews:(UIView *)parentView iconName:(NSString *)imageName title:(NSString*)titleName hint:(NSString*)hintText{
    
    return [self addSubDetailViews:parentView iconName:imageName iconLeft:8 title:titleName titleLeft:16 hint:hintText];
    
}

- (void)tapViewWXPay:(UIGestureRecognizer *)tap {
    
    
}
- (void)tapViewLLPay:(UIGestureRecognizer *)tap {
    
    
}
- (void)tapViewCashPay:(UIGestureRecognizer *)tap {
    
    
    UIAlertController *alerController = [UIAlertController alertControllerWithTitle:@"您确定货到付款吗？" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        PayResultViewController *payResultVC = [[PayResultViewController alloc] init];
        [payResultVC setHidesBottomBarWhenPushed:YES];
        payResultVC.strOrderID = _strItemId;
        payResultVC.strAmount = _strCurAmount;
        payResultVC.orderNum = _orderNum;
        [self.navigationController pushViewController:payResultVC animated:true];

    }];
    
    [alerController addAction:cancleAction];
    [alerController addAction:defaultAction];
    [self  presentViewController:alerController animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
